﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DEMO.Y2015CS58.LIB
{
    public class CalculatorControllers
    {
        /// <summary>
        /// Day la ham tinh toan
        /// </summary>
        /// <param name="a">So A</param>
        /// <param name="b">So B</param>
        /// <param name="iOpt">Thu tu phep toan: 0 la Cong; 1 la Tru; 2 la Nhan; 3 la Chia </param>
        /// <returns></returns>
        public double CalculatorInfo(ref string Message, double soA, double soB, int iOpt)
        {
            double kq = 0;
            string message = "";
            if (iOpt==0)
            {
                kq = soA + soB;
            }
            else if (iOpt == 1)
            {
                kq = soA - soB;
            }
            else if (iOpt == 2)
            {
                kq = soA * soB;
            }
            else
            {
                //
                if (soA != 0 && soB == 0)
                {
                    message = "Cannot divide by zero.";
                    
                }
                else if (soA == 0 && soB == 0)
                {
                    message = "Result of function is underfined.";
                    
                }
                kq = soA / soB;
            }

            Message = message;
            return kq;
        }
    }
}
